package com.bit.aop.demo.proxy;

//import java.lang.reflect.InvocationHandler;
//import java.lang.reflect.Method;

import org.springframework.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

public class JDKInvocationHandler implements InvocationHandler {

    //目标对象
    private Object target;

    public JDKInvocationHandler(Object target) {
        this.target = target;
    }

    //通过代理, 调用目标方法
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是代理, 我开始代理");
        //执行目标方法
        Object result = method.invoke(target, args);
        System.out.println("我是代理, 我结束代理");
        return result;
    }
}
